<?php
include_once('includes/item.php');
$tag=request_var('tag','');
$id=request_var('id',0);
$item = new Item($tag,$id);
$cat=new Category($item->data['catid']);
$inCart=false;
foreach($items_cookie as $it)
{
	if(strpos($it,$item->data['tag'].'-'.$item->data['id'])!==false){
		$inCart=true;
		break;
	}
}
?>

<div class="container">
    <div id="main-content-wrapper">
        <div class="breadcrumb">
		<?php
			for($j=0;$j<count($cat->path);$j++)
				echo '<a href="index.php?p=cat&catid='.$cat->path[$j]['id'].'">'.$cat->path[$j]['catname'].'</a><span>&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;</span>';
			echo '<a href="index.php?p=cat&catid='.$cat->data['id'].'">'.$cat->data['catname'].'</a><span>&nbsp;&nbsp;&rsaquo;&nbsp;&nbsp;</span>';
			$page=request_var('pg',1);
			$items=$cat->GetAllItems(true,$page);
		?>
        </div>

        <div id="title">            
	        <h1><?php echo $cat->data['catname'] . ' &nbsp;&raquo;&nbsp; '.$item->data['name'] . ' '.$item->data['tag'] . ' - '.$item->data['id']; ?></h1>
        </div>
        <div id="rightcontent">
            <div id="product_images">
                <div class="img_big">
				<?php
					echo '<img style="max-width:440px;" src="'.$item->data['img'].'" alt="'.($item->data['name'].' '.$item->data['tag'].'-'.$item->data['id']).'" />';
				?>
                </div>
           </div>
            <div id="product_info">
                <div class="regular-price">
                    <?php
						echo $item->data['price']. ' (VND)';
					?>
                </div>
                <div class="ckout">
                    <div>
                        <label>Số lượng</label>
                        <input type="text" name="qty" id="qty" maxlength="12" value="1" title="Qty" class="input-text qty" />                        
                    </div>
                    <button type="button" title="Mua ngay" onclick="BuyNow(<?php echo "'".$item->data['tag'].'\','.$item->data['id'];?>)">Mua ngay</button><br /><br />                    
                    <a href="javascript:void(0);" onclick="AddToCart(this, <?php echo "'".$item->data['tag'].'\','.$item->data['id'];?>)"<?php if($inCart) echo ' class="line-through"'; ?>>+ Thêm vào giỏ hàng</a>                    

                    <script type="text/javascript">
					//<![CDATA[
                        function AddToCart(el, tag, id) {
							items=GetCookie('items');
							if(items.indexOf(tag+'-'+id)>=0) return;
							items+=tag+'-'+id+'-'+$('#qty').attr('value')+';';
							SetCookie('items',items);
                            $(el).addClass('line-through');
							var k=parseInt($('#spcart').text());
							$('#spcart').text(k+1);
                        }

                        function BuyNow(tag, id) {
                            items=tag+'-'+id+'-'+$('#qty').attr('value')+';';
							SetCookie('items',items);
							window.location='index.php?p=order';
                        }
					//]]>
                    </script>
                </div>
            </div>
            <div class="clear"></div>            
            <div class="breadpage">
				<p>Chi tiết sản phẩm</p>
            </div>
            <br />
            <div class="product-details">
				<div>
				<?php
					echo $item->data['description'];
				?>
				</div>
				<div align="center">
				<?php
					foreach($item->images as $image)
					{
						echo '<img alt="" src="'.$image.'" style="max-with:700px;"/><br/>';
					}
				?>
				</div>
			</div>
        </div>
        <div class="left">
            <div class="boxtiny">		        
		        <div class="body">
					<div class="side-categories">
						<ul>
						<?php
							foreach($cat->sub as $sub)
							{
								echo '<li><a href="index.php?p=cat&catid='.$sub['id'].'">'.$sub['catname'].'</a></li>';
							}
						?>
						</ul>
					</div>
				</div>
	        </div>
        </div>      
        <div class="clear"></div>

    </div>
</div>